package com.zk.algorithm.linkedlist;

import com.zk.algorithm.bean.ListNode;

/**
 * @author zk
 */
public class RemoveDuplicateFromSortedList {

    // Input: 1->1->2->3->3
    // Output: 1->2->3
    public ListNode deleteDuplicates(ListNode head) {
        ListNode cur = head;

        while (cur != null) {
            // 判断下一个节点是否为空
            if (cur.next == null) {
                break;
            }

            // 如果下一个节点的值与当前节点的值相同，则跳过
            if (cur.val == cur.next.val) {
                cur.next = cur.next.next;
            } else {
                cur = cur.next;
            }
        }

        return head;
    }

}
